<!-- src/components/Task/NewTaskListDialog.vue -->
<template>
  <el-dialog
      v-model="visible"
      title="新建任务列表"
      :close-on-click-modal="false"
      :width="300"
      @close="$emit('update:modelValue', false)"
  >
    <el-input
        v-model="localName"
        placeholder="输入名称"
        @keyup.enter="$emit('confirm')"
    />
    <template #footer>
      <el-button @click="$emit('update:modelValue', false)">取消</el-button>
      <el-button type="primary" @click="$emit('confirm')">完成</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue'

const props = defineProps<{
  modelValue: boolean
  newListName: string
}>()

const emit = defineEmits<{
  (e: 'update:modelValue', val: boolean): void
  (e: 'update:newListName', val: string): void
  (e: 'confirm'): void
}>()

const visible = ref(props.modelValue)
const localName = ref(props.newListName)

watch(() => props.modelValue, (val) => {
  visible.value = val
})

watch(() => props.newListName, (val) => {
  localName.value = val
})

watch(localName, (val) => {
  emit('update:newListName', val)
})
</script>